<template>
	<view v-if="Object.keys(album).length > 0">
		<!-- 专辑背景 -->
		<view class="album_bg">
			<image :src="album.cover" mode="widthFix"></image>
			<view class="album_info">
				<view class="album_name">{{album.name}}</view>
				<view class="album_btn">关注专辑</view>
			</view>
		</view>
	
		<!-- 专辑作者 -->
		<view class="album_author">
			<view class="album_title">
				<image :src="album.user.avatar" mode="widthFix"></image>
				<text>{{album.user.name}}</text>
			</view>
			<view class="album_content"><text>{{album.desc}}</text></view>
		</view>
		
		<!-- 图片列表 -->
		<view class="album_list">
			<view class="album_item"
				v-for="item in wallpaper"
				:key="item.id">
				<image mode="widthFix" :src="item.thumb + item.rule.replace('$<Height>', 360)"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					limit: 30,
					order: "new",
					skip: 0,
					// 1 返回值有album对象 表示第一次请求
					// 0 返回值只有 wallpaper数组 不是第一次请求数据
					first: 1
				},
				album: {},
				wallpaper: [],
				hasMore: true
			}
		},
		// 页面触底 上拉加载下一页事件
		onReachBottom() {
			if (this.hasMore) {
				this.params.first = 0
				this.params.skip += this.params.limit
				this.getList()
			} else {
				uni.showToast({
					title: "没有更多数据了",
					icon: "none"
				})
			}
		},
		methods: {
			async getList(id) {
				const { res } = await this.$request({
					url: `http://157.122.54.189:9088/image/v1/wallpaper/album/${id}/wallpaper`,
					data: this.params
				})
				console.log(res)
				if (Object.keys(this.album).length === 0) {
					this.album = res.album
				}
				
				if (res.wallpaper.length === 0) {
					this.hasMore = false
					uni.showToast({
						title: "没有更多数据了",
						icon: "none"
					})
					return false
				}
				
				this.wallpaper = [...this.wallpaper, ...res.wallpaper]
			}
		},
		onLoad(options) {
			// console.log(options)
			this.getList(options.id)
		}
	}
</script>

<style lang="scss" scoped>
.album_bg {
	position: relative;
	image {
		width: 100%;
	}
	.album_info {
		position: absolute;
		width: 100%;
		height: 80rpx;
		padding: 0 15rpx;
		left: 0;
		bottom: 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		color: #ffffff;
		.album_name {
			flex: 1;
			font-size: 40rpx;
		}
		.album_btn {
			padding: 5rpx 10rpx;
			background-color: $color;
			font-size: 30rpx;
			border-radius: 15rpx;
		}
	}
}

.album_author {
	padding: 20rpx 10rpx;
	.album_title {
		padding: 10rpx 0;
		display: flex;
		image {
			width: 50rpx;
		}
		text {
			color: #000;
			margin-left: 15rpx;
		}
	}
}

.album_list {
	display: flex;
	flex-wrap: wrap;
	.album_item {
		width: 33.33%;
		image {
			width: 100%;
			padding: 5rpx;
		}
	}
}
</style>
